//+--------------------------------------------------------------------
//| Copyright(c) 2012 - an.vuongngocduy					
//| This file is a part of Compact Game Engine (CGE)	
//+--------------------------------------------------------------------
#ifndef __CGE_MATH__
#define __CGE_MATH__

#include <math.h>
#include <stdarg.h>
#include "cgeCommons.h"

namespace cge
{
	namespace std
	{
		class Math
		{
		public:
			static const f32 PI;

			static f32 Sqrt(f32 num);

			static f32 Acos(f32 num);

			static f32 Max(f32 n0 , f32 n1);

			static f32 Max(u32 count, ...);

			static f32 Min(f32 n0, f32 n1);

			static f32 Min(u32 count, ...);

			static f32 Floor(f32 num);
		};
	}
	
	// Math class implementation
	namespace std
	{
		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Sqrt(f32 num)
		{
			return sqrt(num);
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Acos(f32 num)
		{
			return acos(num);
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Max(f32 n0, f32 n1)
		{
			return (n0 > n1) ? n0 : n1;
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Max(u32 count, ...)
		{
			va_list vl;
			va_start(vl, count);
			
			f32 max = va_arg(vl, f32);
			for(u32 i = 1; i < count; i++)
			{
				f32 value = va_arg(vl, f32);
				max = ( value > max ) ? value : max;
			}
			
			va_end(vl);	
			return 0;
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Min(f32 n0, f32 n1)
		{
			return (n0 < n1) ? n0 : n1;
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Min(u32 count, ...)
		{
			va_list vl;
			va_start(vl, count);
			
			f32 max = va_arg(vl, f32);
			for(u32 i = 1; i < count; i++)
			{
				f32 value = va_arg(vl, f32);
				max = ( value < max ) ? value : max;
			}
			
			va_end(vl);	
			return 0;
		}

		/*----------------------------------------------------------------------------------------*/
		inline f32 Math::Floor(f32 num)
		{
			return floor(num);
		}
	}
}

#endif//__CGE_MATH__